home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / xulrunner-1.9.0.14 / xulrunner < prev   
Encoding:
Text File  |  2009-09-02  |  7.8 KB  |  290 lines

  1. #!/bin/sh
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is mozilla.org code.
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Netscape Communications Corporation.
  20. # Portions created by the Initial Developer are Copyright (C) 1998
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either the GNU General Public License Version 2 or later (the "GPL"), or
  27. # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38.  
  39. ## $Id: mozilla.in,v 1.4 2008/01/07 23:17:05 reed%reedloden.com Exp $
  40. ## 
  41. ## Usage:
  42. ##
  43. ## $ mozilla [args]
  44. ##
  45. ## This script is meant to run the mozilla-bin binary from either 
  46. ## mozilla/xpfe/bootstrap or mozilla/dist/bin.
  47. ##
  48. ## The script will setup all the environment voodoo needed to make
  49. ## the mozilla-bin binary to work.
  50. ##
  51.  
  52. moz_pis_startstop_scripts()
  53. {
  54.   MOZ_USER_DIR=".mozilla/xulrunner"
  55.   # MOZ_PIS_ is the name space for "Mozilla Plugable Init Scripts"
  56.   # These variables and there meaning are specified in
  57.   # mozilla/xpfe/bootstrap/init.d/README
  58.   MOZ_PIS_API=2
  59.   MOZ_PIS_MOZBINDIR="${dist_bin}"
  60.   MOZ_PIS_SESSION_PID="$$"
  61.   MOZ_PIS_USER_DIR="${MOZ_USER_DIR}"
  62.   export MOZ_PIS_API MOZ_PIS_MOZBINDIR MOZ_PIS_SESSION_PID MOZ_PIS_USER_DIR
  63.   
  64.   case "${1}" in
  65.     "start")
  66.       for curr_pis in "${dist_bin}/init.d"/S* "${HOME}/${MOZ_USER_DIR}/init.d"/S* ; do
  67.         if [ -x "${curr_pis}" ] ; then
  68.           case "${curr_pis}" in
  69.             *.sh) .  "${curr_pis}"         ;;
  70.             *)       "${curr_pis}" "start" ;;
  71.           esac
  72.         fi
  73.       done
  74.       ;;
  75.     "stop")
  76.       for curr_pis in "${HOME}/${MOZ_USER_DIR}/init.d"/K* "${dist_bin}/init.d"/K* ; do
  77.         if [ -x "${curr_pis}" ] ; then
  78.           case "${curr_pis}" in
  79.             *.sh) . "${curr_pis}"        ;;
  80.             *)      "${curr_pis}" "stop" ;;
  81.           esac
  82.         fi
  83.       done
  84.       ;;
  85.     *)
  86.       echo 1>&2 "$0: Internal error in moz_pis_startstop_scripts."
  87.       exit 1
  88.       ;;
  89.   esac
  90. }
  91.  
  92. #uncomment for debugging
  93. #set -x
  94.  
  95. moz_libdir=
  96. MRE_HOME=
  97.  
  98. # Use run-mozilla.sh in the current dir if it exists
  99. # If not, then start resolving symlinks until we find run-mozilla.sh
  100. found=0
  101. progname="$0"
  102. curdir=`dirname "$progname"`
  103. progbase=`basename "$progname"`
  104. profile=""
  105. run_moz="$curdir/run-mozilla.sh"
  106. if test -x "$run_moz"; then
  107.   dist_bin="$curdir"
  108.   found=1
  109. else
  110.   here=`/bin/pwd`
  111.   while [ -h "$progname" ]; do
  112.     bn=`basename "$progname"`
  113.     cd `dirname "$progname"`
  114.     progname=`/bin/ls -l "$bn" | sed -e 's/^.* -> //' `
  115.     progbase=`basename "$progname"`
  116.     if [ ! -x "$progname" ]; then
  117.       break
  118.     fi
  119.     curdir=`dirname "$progname"`
  120.     run_moz="$curdir/run-mozilla.sh"
  121.     if [ -x "$run_moz" ]; then
  122.       cd "$curdir"
  123.       dist_bin=`pwd`
  124.       found=1
  125.       break
  126.     fi
  127.   done
  128.   cd "$here"
  129. fi
  130. if [ $found = 0 ]; then
  131.   # Check default compile-time libdir
  132.   if [ -x "$moz_libdir/run-mozilla.sh" ]; then
  133.     dist_bin="$moz_libdir"
  134.   else 
  135.     echo "Cannot find mozilla runtime directory. Exiting."
  136.     exit 1
  137.   fi
  138. fi
  139.  
  140. script_args=""
  141. debugging=0
  142. MOZILLA_BIN="${progbase}-bin"
  143. MOZ_CLIENT_PROGRAM="$dist_bin/mozilla-xremote-client"
  144.  
  145. run_xremote_client() {
  146.   if [ -n "${profile}" ]; then
  147.     "${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" -p "${profile}" "$1"
  148.   else
  149.     "${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" "$1"
  150.   fi
  151. }
  152.  
  153. # The following is to check for a currently running instance.
  154. # This is taken almost verbatim from the Mozilla RPM package's launch script.
  155. check_running() {
  156.     run_xremote_client 'ping()' 2>/dev/null >/dev/null
  157.     RETURN_VAL=$?
  158.     if [ $RETURN_VAL -eq 0 ]; then
  159.         echo 1
  160.         return 1
  161.     else
  162.         echo 0
  163.         return 0
  164.     fi
  165. }
  166.  
  167. if [ "$OSTYPE" = "beos" ]; then
  168.   mimeset -F "$MOZILLA_BIN"
  169. fi
  170.  
  171. ################################################################ Parse Arguments
  172. # If there's a command line argument but it doesn't begin with a -
  173. # it's probably a url.  Try to send it to a running instance.
  174. _USE_EXIST=0
  175. _NEW_WINDOW=
  176. _optOne="$1"
  177. case "${_optOne}" in
  178.     -*) 
  179.         ;;
  180.     *)
  181.         _USE_EXIST=1
  182.         ;;
  183. esac
  184.  
  185. _optOthers=
  186. _optLast=
  187. for i in "$@"; do 
  188.     _optLast="${i}"
  189. done #last arg
  190.  
  191. for i in "$@"; do
  192.     [ "$i" = "${_optLast}" ] && break
  193.     _optOthers="${_optOthers} ${i}"
  194. done #others arg
  195.  
  196. #???: needs check if othersopt begin with -* ?
  197. if [ `expr "${_optLast}" : '.*:/.*'` -eq 0 -a \( -f "${_optLast}" -o -d "${_optLast}" \) ]; then
  198.     # Last argument seems to be a local file/directory
  199.     # Check, if it is absolutely specified (ie. /home/foo/file vs. ./file)
  200.     # If it is just "relatively" (./file) specified, make it absolutely
  201.     [ `expr "${_optLast}" : '/.*'` -eq 0 ] && _optLast="file://`pwd`/${_optLast}"
  202. elif [ `expr "${_optLast}" : '.*:/.*'` -gt 0 -o -n "${_optOthers}" ]; then #???? like before...
  203.     _NEW_WINDOW=1
  204. fi
  205.  
  206. # check for -P argument used to select a user profile
  207. _expectProfileName=0
  208. for i in "$@"; do
  209.   if [ "$i" = "-P" ]; then
  210.     _expectProfileName=1
  211.     profile=""
  212.   elif [ ${_expectProfileName} = 1 ]; then
  213.     _expectProfileName=0
  214.     profile="$i"
  215.   fi
  216. done
  217.  
  218. ################################################################ Parse Arguments
  219.  
  220. ########################################################################### Main
  221. ALREADY_RUNNING=`check_running`
  222.  
  223. if [ $ALREADY_RUNNING -eq 1 ]; then
  224.     # There's an instance already running. Use it.
  225.     # Any command line args passed in?
  226.     if [ $# -gt 0 ]; then
  227.         # There were "some" command line args.
  228.         if [ ${_USE_EXIST} -eq 1 ]; then
  229.             # We should use an existing instance, as _USE_EXIST=$_USE_EXIST=-1
  230.             _open_type="window"
  231.             #_open_type="tab"
  232.             _remote_cmd="openURL(${_optLast} , new-${_open_type})"
  233.       run_xremote_client "${_remote_cmd}"
  234.             unset _remote_cmd _open_type
  235.             exit $?
  236.         fi
  237.     else
  238.         # No command line args. Open new window/tab
  239.     run_xremote_client "xfeDoCommand(openBrowser)"
  240.         exit $?
  241.     fi
  242. fi
  243. # Default action - no running instance or _USE_EXIST (${_USE_EXIST}) ! -eq 1
  244. ########################################################################### Main
  245.  
  246. pass_arg_count=0
  247. while [ $# -gt $pass_arg_count ]
  248. do
  249.   case "$1" in
  250.     -p | --pure | -pure)
  251.       MOZILLA_BIN="${MOZILLA_BIN}.pure"
  252.       shift
  253.       ;;
  254.     -g | --debug)
  255.       script_args="$script_args -g"
  256.       debugging=1
  257.       shift
  258.       ;;
  259.     -d | --debugger)
  260.       script_args="$script_args -d $2"
  261.       shift 2
  262.       ;;
  263.     *)
  264.       # Move the unrecognized argument to the end of the list.
  265.       arg="$1"
  266.       shift
  267.       set -- "$@" "$arg"
  268.       pass_arg_count=`expr $pass_arg_count + 1`
  269.       ;;
  270.   esac
  271. done
  272.  
  273. export MRE_HOME
  274.  
  275. ## Start addon scripts
  276. moz_pis_startstop_scripts "start"
  277.  
  278. if [ $debugging = 1 ]
  279. then
  280.   echo $dist_bin/run-mozilla.sh $script_args $dist_bin/$MOZILLA_BIN "$@"
  281. fi
  282. "$dist_bin/run-mozilla.sh" $script_args "$dist_bin/$MOZILLA_BIN" "$@"
  283. exitcode=$?
  284.  
  285. ## Stop addon scripts
  286. moz_pis_startstop_scripts "stop"
  287.  
  288. exit $exitcode
  289. # EOF.
  290.